home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / imap / non-ANSI / c-client / bezerk.h < prev    next >
Text File  |  1995-04-13  |  11KB  |  292 lines

  1. /*
  2.  * Program:    Berkeley mail routines
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        Networks and Distributed Computing
  6.  *        Computing & Communications
  7.  *        University of Washington
  8.  *        Administration Building, AG-44
  9.  *        Seattle, WA  98195
  10.  *        Internet: MRC@CAC.Washington.EDU
  11.  *
  12.  * Date:    20 December 1989
  13.  * Last Edited:    12 April 1995
  14.  *
  15.  * Copyright 1995 by the University of Washington
  16.  *
  17.  *  Permission to use, copy, modify, and distribute this software and its
  18.  * documentation for any purpose and without fee is hereby granted, provided
  19.  * that the above copyright notice appears in all copies and that both the
  20.  * above copyright notice and this permission notice appear in supporting
  21.  * documentation, and that the name of the University of Washington not be
  22.  * used in advertising or publicity pertaining to distribution of the software
  23.  * without specific, written prior permission.  This software is made
  24.  * available "as is", and
  25.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  26.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  27.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  28.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  29.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  30.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  31.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  32.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  33.  *
  34.  */
  35.  
  36.  
  37. /* Dedication:
  38.  *  This file is dedicated with affection to those Merry Marvels of Musical
  39.  * Madness . . .
  40.  *  ->  The Incomparable Leland Stanford Junior University Marching Band  <-
  41.  * who entertain, awaken, and outrage Stanford fans in the fact of repeated
  42.  * losing seasons and shattered Rose Bowl dreams [Cardinal just don't have
  43.  * HUSKY FEVER!!!].
  44.  *
  45.  */
  46.  
  47. /* Validate line
  48.  * Accepts: pointer to candidate string to validate as a From header
  49.  *        return pointer to end of date/time field
  50.  *        return pointer to offset from t of time (hours of ``mmm dd hh:mm'')
  51.  *        return pointer to offset from t of time zone (if non-zero)
  52.  * Returns: t,ti,zn set if valid From string, else ti is NIL
  53.  */
  54.  
  55. #define VALID(s,x,ti,zn) {                        \
  56.   ti = 0;                                \
  57.   if ((*s == 'F') && (s[1] == 'r') && (s[2] == 'o') && (s[3] == 'm') &&    \
  58.       (s[4] == ' ')) {                            \
  59.     for (x = s + 5; *x && *x != '\n'; x++);                \
  60.     if (*x) {                                \
  61.       if (x - s >= 41) {                        \
  62.     for (zn = -1; x[zn] != ' '; zn--);                \
  63.     if ((x[zn-1] == 'm') && (x[zn-2] == 'o') && (x[zn-3] == 'r') &&    \
  64.         (x[zn-4] == 'f') && (x[zn-5] == ' ') && (x[zn-6] == 'e') &&    \
  65.         (x[zn-7] == 't') && (x[zn-8] == 'o') && (x[zn-9] == 'm') &&    \
  66.         (x[zn-10] == 'e') && (x[zn-11] == 'r') && (x[zn-12] == ' '))\
  67.       x += zn - 12;                            \
  68.       }                                    \
  69.       if (x - s >= 27) {                        \
  70.     if (x[-5] == ' ') {                        \
  71.       if (x[-8] == ':') zn = 0,ti = -5;                \
  72.       else if (x[-9] == ' ') ti = zn = -9;                \
  73.       else if ((x[-11] == ' ') && ((x[-10]=='+') || (x[-10]=='-')))    \
  74.         ti = zn = -11;                        \
  75.     }                                \
  76.     else if (x[-4] == ' ') {                    \
  77.       if (x[-9] == ' ') zn = -4,ti = -9;                \
  78.     }                                \
  79.     else if (x[-6] == ' ') {                    \
  80.       if ((x[-11] == ' ') && ((x[-5] == '+') || (x[-5] == '-')))    \
  81.         zn = -6,ti = -11;                        \
  82.     }                                \
  83.     if (ti && !((x[ti - 3] == ':') &&                \
  84.             (x[ti -= ((x[ti - 6] == ':') ? 9 : 6)] == ' ') &&    \
  85.             (x[ti - 3] == ' ') && (x[ti - 7] == ' ') &&        \
  86.             (x[ti - 11] == ' '))) ti = 0;            \
  87.       }                                    \
  88.     }                                    \
  89.   }                                    \
  90. }
  91.  
  92. /* You are not expected to understand this macro, but read the next page if
  93.  * you are not faint of heart.
  94.  *
  95.  * Known formats to the VALID macro are:
  96.  *         From user Wed Dec  2 05:53 1992
  97.  * BSD        From user Wed Dec  2 05:53:22 1992
  98.  * SysV        From user Wed Dec  2 05:53 PST 1992
  99.  * rn        From user Wed Dec  2 05:53:22 PST 1992
  100.  *        From user Wed Dec  2 05:53 -0700 1992
  101.  *        From user Wed Dec  2 05:53:22 -0700 1992
  102.  *        From user Wed Dec  2 05:53 1992 PST
  103.  *        From user Wed Dec  2 05:53:22 1992 PST
  104.  *        From user Wed Dec  2 05:53 1992 -0700
  105.  * Solaris    From user Wed Dec  2 05:53:22 1992 -0700
  106.  *
  107.  * Plus all of the above with `` remote from xxx'' after it. Thank you very
  108.  * much, smail and Solaris, for making my life considerably more complicated.
  109.  */
  110.  
  111. /*
  112.  * What?  You want to understand the VALID macro anyway?  Alright, since you
  113.  * insist.  Actually, it isn't really all that difficult, provided that you
  114.  * take it step by step.
  115.  *
  116.  * Line 1    Initializes the return ti value to failure (0);
  117.  * Lines 2-3    Validates that the 1st-5th characters are ``From ''.
  118.  * Lines 4-5    Validates that there is an end of line and points x at it.
  119.  * Lines 6-13    First checks to see if the line is at least 41 characters long.
  120.  *        If so, it scans backwards to find the rightmost space.  From
  121.  *        that point, it scans backwards to see if the string matches
  122.  *        `` remote from''.  If so, it sets x to point to the space at
  123.  *        the start of the string.
  124.  * Line 14    Makes sure that there are at least 27 characters in the line.
  125.  * Lines 15-20    Checks if the date/time ends with the year (there is a space
  126.  *        five characters back).  If there is a colon three characters
  127.  *        further back, there is no timezone field, so zn is set to 0
  128.  *        and ti is set in front of the year.  Otherwise, there must
  129.  *        either to be a space four characters back for a three-letter
  130.  *        timezone, or a space six characters back followed by a + or -
  131.  *        for a numeric timezone; in either case, zn and ti become the
  132.  *        offset of the space immediately before it.
  133.  * Lines 21-23    Are the failure case for line 14.  If there is a space four
  134.  *        characters back, it is a three-letter timezone; there must be a
  135.  *        space for the year nine characters back.  zn is the zone
  136.  *        offset; ti is the offset of the space.
  137.  * Lines 24-27    Are the failure case for line 20.  If there is a space six
  138.  *        characters back, it is a numeric timezone; there must be a
  139.  *        space eleven characters back and a + or - five characters back.
  140.  *        zn is the zone offset; ti is the offset of the space.
  141.  * Line 28-31    If ti is valid, make sure that the string before ti is of the
  142.  *        form www mmm dd hh:mm or www mmm dd hh:mm:ss, otherwise
  143.  *        invalidate ti.  There must be a colon three characters back
  144.  *        and a space six or nine    characters back (depending upon
  145.  *        whether or not the character six characters back is a colon).
  146.  *        There must be a space three characters further back (in front
  147.  *        of the day), one seven characters back (in front of the month),
  148.  *        and one eleven characters back (in front of the day of week).
  149.  *        ti is set to be the offset of the space before the time.
  150.  *
  151.  * Why a macro?  It gets invoked a *lot* in a tight loop.  On some of the
  152.  * newer pipelined machines it is faster being open-coded than it would be if
  153.  * subroutines are called.
  154.  *
  155.  * Why does it scan backwards from the end of the line, instead of doing the
  156.  * much easier forward scan?  There is no deterministic way to parse the
  157.  * ``user'' field, because it may contain unquoted spaces!  Yes, I tested it to
  158.  * see if unquoted spaces were possible.  They are, and I've encountered enough
  159.  * evil mail to be totally unwilling to trust that ``it will never happen''.
  160.  */
  161.  
  162. /* Build parameters */
  163.  
  164. #define KODRETRY 15        /* kiss-of-death retry in seconds */
  165. #define LOCKTIMEOUT 5        /* lock timeout in minutes */
  166. #define CHUNK 32768        /* read-in chunk size */
  167.  
  168.  
  169. /* Command bits from bezerk_getflags() */
  170.  
  171. #define fSEEN 1
  172. #define fDELETED 2
  173. #define fFLAGGED 4
  174. #define fANSWERED 8
  175.  
  176.  
  177. /* Status string */
  178.  
  179. #define STATUS "Status: RO\nX-Status: DFA\n\n"
  180.  
  181. /* BEZERK per-message cache information */
  182.  
  183. typedef struct file_cache {
  184.   char *header;            /* pointer to RFC 822 header */
  185.   unsigned long headersize;    /* size of RFC 822 header */
  186.   char *body;            /* pointer to message body */
  187.   unsigned long bodysize;    /* size of message body */
  188.   char status[sizeof (STATUS)];    /* status flags */
  189.   char internal[1];        /* start of internal header and data */
  190. } FILECACHE;
  191.  
  192.  
  193. /* BEZERK I/O stream local data */
  194.  
  195. typedef struct bezerk_local {
  196.   unsigned int dirty : 1;    /* disk copy needs updating */
  197.   int ld;            /* lock file descriptor */
  198.   char *name;            /* local file name for recycle case */
  199.   char *lname;            /* lock file name */
  200.   off_t filesize;        /* file size parsed */
  201.   time_t filetime;        /* last file time */
  202.   unsigned long cachesize;    /* size of local cache */
  203.   FILECACHE **msgs;        /* pointers to message-specific information */
  204.   char *buf;            /* temporary buffer */
  205.   unsigned long buflen;        /* current size of temporary buffer */
  206. } BEZERKLOCAL;
  207.  
  208.  
  209. /* Convenient access to local data */
  210.  
  211. #define LOCAL ((BEZERKLOCAL *) stream->local)
  212.  
  213. /* Function prototypes */
  214.  
  215. DRIVER *bezerk_valid  ();
  216. int bezerk_isvalid  ();
  217. long bezerk_isvalid_fd  ();
  218. void *bezerk_parameters  ();
  219. void bezerk_find  ();
  220. void bezerk_find_bboards  ();
  221. void bezerk_find_all  ();
  222. void bezerk_find_all_bboards  ();
  223. long bezerk_subscribe  ();
  224. long bezerk_unsubscribe  ();
  225. long bezerk_subscribe_bboard  ();
  226. long bezerk_unsubscribe_bboard  ();
  227. long bezerk_create  ();
  228. long bezerk_delete  ();
  229. long bezerk_rename  ();
  230. MAILSTREAM *bezerk_open  ();
  231. void bezerk_close  ();
  232. void bezerk_fetchfast  ();
  233. void bezerk_fetchflags  ();
  234. ENVELOPE *bezerk_fetchstructure  ();
  235. char *bezerk_snarf  ();
  236. char *bezerk_fetchheader  ();
  237. char *bezerk_fetchtext  ();
  238. char *bezerk_fetchbody ();
  239. void bezerk_setflag  ();
  240. void bezerk_clearflag  ();
  241. void bezerk_search  ();
  242. long bezerk_ping  ();
  243. void bezerk_check  ();
  244. void bezerk_expunge  ();
  245. long bezerk_copy  ();
  246. long bezerk_move  ();
  247. long bezerk_append  ();
  248. long bezerk_append_putc  ();
  249. void bezerk_gc  ();
  250.  
  251. void bezerk_abort  ();
  252. char *bezerk_file  ();
  253. int bezerk_lock  ();
  254. void bezerk_unlock  ();
  255. int bezerk_parse  ();
  256. char *bezerk_eom  ();
  257. int bezerk_extend  ();
  258. void bezerk_save  ();
  259. int bezerk_copy_messages  ();
  260. int bezerk_write_message  ();
  261. void bezerk_update_status  ();
  262. short bezerk_getflags  ();
  263. char bezerk_search_all  ();
  264. char bezerk_search_answered  ();
  265. char bezerk_search_deleted  ();
  266. char bezerk_search_flagged  ();
  267. char bezerk_search_keyword  ();
  268. char bezerk_search_new  ();
  269. char bezerk_search_old  ();
  270. char bezerk_search_recent  ();
  271. char bezerk_search_seen  ();
  272. char bezerk_search_unanswered  ();
  273. char bezerk_search_undeleted  ();
  274. char bezerk_search_unflagged  ();
  275. char bezerk_search_unkeyword  ();
  276. char bezerk_search_unseen  ();
  277. char bezerk_search_before  ();
  278. char bezerk_search_on  ();
  279. char bezerk_search_since  ();
  280. char bezerk_search_body  ();
  281. char bezerk_search_subject  ();
  282. char bezerk_search_text  ();
  283. char bezerk_search_bcc  ();
  284. char bezerk_search_cc  ();
  285. char bezerk_search_from  ();
  286. char bezerk_search_to  ();
  287.  
  288. typedef char (*search_t)  ();
  289. search_t bezerk_search_date  ();
  290. search_t bezerk_search_flag  ();
  291. search_t bezerk_search_string  ();
  292.